package besteAukera;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;

public class BusBitarHamartar extends AteLogikoak {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea ;
	private Vector<Hanka> sarreraBektorea;
	private Hanka s1, s2, s3, s4, s5, s6, s7, s8, i1;
	private boolean aldatua;
	Vector<Integer> bitarBektorea;
private String logika;
	public BusBitarHamartar(int x1, int y1, int hankaKop, int sarreraKop,
			String motaFis, Color kolo,String log) {
		super(x1, y1, hankaKop, sarreraKop, motaFis, kolo);
logika=log;
		aldatua=false;
		kolorea=kolo;
		if (getSarreraKopMax()== 2) {
			
		
				s1 = new Hanka(x, y, logika, "s", 0, this, "h", "ez", true);
				s2 = new Hanka(x, y + 10, logika, "s", 1, this, "h", "ez", true);
				i1 = new Hanka(x+40 , y + 5, logika, "i", 2, this, "h", "ez",
						false);
				
				lotList[0] = s1;
				lotList[1] = s2;
				lotList[2] = i1;
						
		} else if (getSarreraKopMax() == 3) {
			
			s1 = new Hanka(x, y, logika, "s", 0, this, "h", "ez", true);
			s2 = new Hanka(x, y + 10, logika, "s", 1, this, "h", "ez", true);
			s3 = new Hanka(x, y + 20, logika, "s", 2, this, "h", "ez", true);
			i1 = new Hanka(x + 40, y + 10, logika, "i", 3, this, "h", "ez",
					false);
			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = i1;

		} else if (getSarreraKopMax() == 4) {
			
			s1 = new Hanka(x, y, logika, "s", 0, this, "h", "ez", true);
			s2 = new Hanka(x, y + 10, logika, "s", 1, this, "h", "ez", true);
			s3 = new Hanka(x, y + 20, logika, "s", 2, this, "h", "ez", true);
			s4 = new Hanka(x, y + 30, logika, "s", 3, this, "h", "ez", true);
			i1 = new Hanka(x + 40, y + 15, logika, "i", 4, this, "h", "ez",
					false);
			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			lotList[4] = i1;
		} else if (getSarreraKopMax() == 5) {
			
			s1 = new Hanka(x, y, logika, "s", 0, this, "h", "ez", true);
			s2 = new Hanka(x, y + 10, logika, "s", 1, this, "h", "ez", true);
			s3 = new Hanka(x, y + 20, logika, "s", 2, this, "h", "ez", true);
			s4 = new Hanka(x, y + 30, logika, "s", 3, this, "h", "ez", true);
			s5 = new Hanka(x, y + 40, logika, "s", 4, this, "h", "ez", true);
			i1 = new Hanka(x + 40, y + 20, logika, "i", 5, this, "h", "ez",
					false);
			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			lotList[4] = s5;
			lotList[5] = i1;

		} else if (getSarreraKopMax() == 6) {
			
			s1 = new Hanka(x, y, logika, "s", 0, this, "h", "ez", true);
			s2 = new Hanka(x, y + 10, logika, "s", 1, this, "h", "ez", true);
			s3 = new Hanka(x, y + 20, logika, "s", 2, this, "h", "ez", true);
			s4 = new Hanka(x, y + 30, logika, "s", 3, this, "h", "ez", true);
			s5 = new Hanka(x, y + 40, logika, "s", 4, this, "h", "ez", true);
			s6 = new Hanka(x, y + 50, logika, "s", 5, this, "h", "ez", true);
			i1 = new Hanka(x + 40, y + 25, logika, "i", 6, this, "h", "ez",
					false);
			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			lotList[4] = s5;
			lotList[5] = s6;
			lotList[6] = i1;

		} else if (getSarreraKopMax() == 7) {
			
			s1 = new Hanka(x, y, logika, "s", 0, this, "h", "ez", true);
			s2 = new Hanka(x, y + 10, logika, "s", 1, this, "h", "ez", true);
			s3 = new Hanka(x, y + 20, logika, "s", 2, this, "h", "ez", true);
			s4 = new Hanka(x, y + 30, logika, "s", 3, this, "h", "ez", true);
			s5 = new Hanka(x, y + 40, logika, "s", 4, this, "h", "ez", true);
			s6 = new Hanka(x, y + 50, logika, "s", 5, this, "h", "ez", true);
			s7 = new Hanka(x, y + 60, logika, "s", 6, this, "h", "ez", true);
			i1 = new Hanka(x + 40, y + 30, logika, "i", 7, this, "h", "ez",
					false);
			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			lotList[4] = s5;
			lotList[5] = s6;
			lotList[6] = s7;
			lotList[7] = i1;

		} else if (getSarreraKopMax()== 8) {
			
			s1 = new Hanka(x, y, logika, "s", 0, this, "h", "ez", true);
			s2 = new Hanka(x, y + 10, logika, "s", 1, this, "h", "ez", true);
			s3 = new Hanka(x, y + 20, logika, "s", 2, this, "h", "ez", true);
			s4 = new Hanka(x, y + 30, logika, "s", 3, this, "h", "ez", true);
			s5 = new Hanka(x, y + 40, logika, "s", 4, this, "h", "ez", true);
			s6 = new Hanka(x, y + 50, logika, "s", 5, this, "h", "ez", true);
			s7 = new Hanka(x, y + 60, logika, "s", 6, this, "h", "ez", true);
			s8 = new Hanka(x, y + 70, logika, "s", 7, this, "h", "ez", true);
			i1 = new Hanka(x + 40, y + 35, logika, "i", 8
					, this, "h", "ez",
					false);
			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			lotList[4] = s5;
			lotList[5] = s6;
			lotList[6] = s7;
			lotList[7] = s8;
			lotList[8] = i1;

		}
		
		// TODO Auto-generated constructor stub
	}

	public void marraztu(Graphics g) {
		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		g.setColor(kolorea);
		if (getSarreraKopMax() == 2) {
			g.drawLine(x + 20, y, x + 20, y + 10);
		
			
			s1.marraztu(g);
			s2.marraztu(g);
			i1.marraztu(g);}
			else if (getSarreraKopMax() == 3) {
			g.drawLine(x + 20, y, x + 20, y + 20);
			
			s1.marraztu(g);
			s2.marraztu(g);
			s3.marraztu(g);
			i1.marraztu(g);
			
			
		} else if (getSarreraKopMax() == 4) {
			g.drawLine(x + 20, y, x + 20, y + 30);
		
			s1.marraztu(g);
			s2.marraztu(g);
			s3.marraztu(g);
			s4.marraztu(g);
			i1.marraztu(g);
		
		} else if (getSarreraKopMax() == 5) {
			g.drawLine(x + 20, y, x + 20, y + 40);
			
				s1.marraztu(g);
				s2.marraztu(g);
				s3.marraztu(g);
				s4.marraztu(g);
				s5.marraztu(g);
				i1.marraztu(g);
		} else if (getSarreraKopMax() == 6) {
			g.drawLine(x + 20, y, x + 20, y + 50);
			
			s1.marraztu(g);
			s2.marraztu(g);
			s3.marraztu(g);
			s4.marraztu(g);
			s5.marraztu(g);
			s6.marraztu(g);
			i1.marraztu(g);
		} else if (getSarreraKopMax() == 7) {
			g.drawLine(x + 20, y, x + 20, y + 60);
			
			s1.marraztu(g);
			s2.marraztu(g);
			s3.marraztu(g);
			s4.marraztu(g);
			s5.marraztu(g);
			s6.marraztu(g);
			s7.marraztu(g);
			i1.marraztu(g);
		} else if (getSarreraKopMax() == 8) {
			g.drawLine(x + 20, y, x + 20, y + 70);
			
			s1.marraztu(g);
			s2.marraztu(g);
			s3.marraztu(g);
			s4.marraztu(g);
			s5.marraztu(g);
			s6.marraztu(g);
			s7.marraztu(g);
			s8.marraztu(g);
			i1.marraztu(g);
		}
	}
	public boolean isAldatua(){
		return aldatua;
	}
	public void setAldatua(boolean ald){
		
		aldatua=ald;
	}
	@Override
	protected void funtzioLogikoa(Integer... values) {
		// TODO Auto-generated method stub
		
		if (getSarreraKopMax() == 2) {
			lotList[2].getIrteera().setBalioa((int)(s1.getSarrera().getBalioa()*Math.pow(2, 0))+(int)(s2.getSarrera().getBalioa()*Math.pow(2, 1)));
		} else if (getSarreraKopMax() == 3) {
			lotList[3].getIrteera().setBalioa((int)(s1.getSarrera().getBalioa()*Math.pow(2, 0))+(int)(s2.getSarrera().getBalioa()*Math.pow(2, 1))+(int)(s3.getSarrera().getBalioa()*Math.pow(2, 2)));
		} else if (getSarreraKopMax() == 4) {
			lotList[4].getIrteera().setBalioa((int)(s1.getSarrera().getBalioa()*Math.pow(2, 0))+(int)(s2.getSarrera().getBalioa()*Math.pow(2, 1))+(int)(s3.getSarrera().getBalioa()*Math.pow(2, 2))+(int)(s4.getSarrera().getBalioa()*Math.pow(2, 3)));
		} else if (getSarreraKopMax() == 5) {
			lotList[5].getIrteera().setBalioa((int)(s1.getSarrera().getBalioa()*Math.pow(2, 0))+(int)(s2.getSarrera().getBalioa()*Math.pow(2, 1))+(int)(s3.getSarrera().getBalioa()*Math.pow(2, 2))+(int)(s4.getSarrera().getBalioa()*Math.pow(2, 3))+(int)(s5.getSarrera().getBalioa()*Math.pow(2, 4)));
		} else if (getSarreraKopMax() == 6) {
			lotList[6].getIrteera().setBalioa((int)(s1.getSarrera().getBalioa()*Math.pow(2, 0))+(int)(s2.getSarrera().getBalioa()*Math.pow(2, 1))+(int)(s3.getSarrera().getBalioa()*Math.pow(2, 2))+(int)(s4.getSarrera().getBalioa()*Math.pow(2, 3))+(int)(s5.getSarrera().getBalioa()*Math.pow(2, 4))+(int)(s6.getSarrera().getBalioa()*Math.pow(2, 5)));
		} else if (getSarreraKopMax() == 7) {
			lotList[7].getIrteera().setBalioa((int)(s1.getSarrera().getBalioa()*Math.pow(2, 0))+(int)(s2.getSarrera().getBalioa()*Math.pow(2, 1))+(int)(s3.getSarrera().getBalioa()*Math.pow(2, 2))+(int)(s4.getSarrera().getBalioa()*Math.pow(2, 3))+(int)(s5.getSarrera().getBalioa()*Math.pow(2, 4))+(int)(s6.getSarrera().getBalioa()*Math.pow(2, 5))+(int)(s7.getSarrera().getBalioa()*Math.pow(2, 6)));
		} else if (getSarreraKopMax() == 8) {
			lotList[8].getIrteera().setBalioa((int)(s1.getSarrera().getBalioa()*Math.pow(2, 0))+(int)(s2.getSarrera().getBalioa()*Math.pow(2, 1))+(int)(s3.getSarrera().getBalioa()*Math.pow(2, 2))+(int)(s4.getSarrera().getBalioa()*Math.pow(2, 3))+(int)(s5.getSarrera().getBalioa()*Math.pow(2, 4))+(int)(s6.getSarrera().getBalioa()*Math.pow(2, 5))+(int)(s7.getSarrera().getBalioa()*Math.pow(2, 6))+(int)(s8.getSarrera().getBalioa()*Math.pow(2, 7)));
		}
		
			
	}
	
	

	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub
		hankaBektorea = new Vector<Hanka>();
		if (getSarreraKopMax() == 2) {
		
			hankaBektorea.add(s1);
			hankaBektorea.add(s2);
			hankaBektorea.add(i1);
		} else if (getSarreraKopMax() == 3) {
			
			hankaBektorea.add(s1);
			hankaBektorea.add(s2);
			hankaBektorea.add(s3);
			hankaBektorea.add(i1);
		} else if (getSarreraKopMax() == 4) {
		
			hankaBektorea.add(s1);
			hankaBektorea.add(s2);
			hankaBektorea.add(s3);
			hankaBektorea.add(s4);
			hankaBektorea.add(i1);

		} else if (getSarreraKopMax() == 5) {
		
			hankaBektorea.add(s1);
			hankaBektorea.add(s2);
			hankaBektorea.add(s3);
			hankaBektorea.add(s4);
			hankaBektorea.add(s5);
			hankaBektorea.add(i1);
		} else if (getSarreraKopMax() == 6) {
			
			hankaBektorea.add(s1);
			hankaBektorea.add(s2);
			hankaBektorea.add(s3);
			hankaBektorea.add(s4);
			hankaBektorea.add(s5);
			hankaBektorea.add(s6);
			hankaBektorea.add(i1);
		} else if (getSarreraKopMax() == 7) {
			
			hankaBektorea.add(s1);
			hankaBektorea.add(s2);
			hankaBektorea.add(s3);
			hankaBektorea.add(s4);
			hankaBektorea.add(s5);
			hankaBektorea.add(s6);
			hankaBektorea.add(s7);
			hankaBektorea.add(i1);

		} else if (getSarreraKopMax() == 8) {
			
			hankaBektorea.add(s1);
			hankaBektorea.add(s2);
			hankaBektorea.add(s3);
			hankaBektorea.add(s4);
			hankaBektorea.add(s5);
			hankaBektorea.add(s6);
			hankaBektorea.add(s7);
			hankaBektorea.add(s8);
			hankaBektorea.add(i1);
		}
		return hankaBektorea;
	}

	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub
		sarreraBektorea = new Vector<Hanka>();
	
		if (getSarreraKopMax() == 2) {
		
			sarreraBektorea.add(s1);
			sarreraBektorea.add(s2);

		} else if (getSarreraKopMax() == 3) {
			sarreraBektorea.add(s1);
			sarreraBektorea.add(s2);
			sarreraBektorea.add(s3);

		} else if (getSarreraKopMax() == 4) {
			sarreraBektorea.add(s1);
			sarreraBektorea.add(s2);
			sarreraBektorea.add(s3);
			sarreraBektorea.add(s4);

		} else if (getSarreraKopMax() == 5) {
			sarreraBektorea.add(s1);
			sarreraBektorea.add(s2);
			sarreraBektorea.add(s3);
			sarreraBektorea.add(s4);
			sarreraBektorea.add(s5);

		} else if (getSarreraKopMax() == 6) {
			sarreraBektorea.add(s1);
			sarreraBektorea.add(s2);
			sarreraBektorea.add(s3);
			sarreraBektorea.add(s4);
			sarreraBektorea.add(s5);
			sarreraBektorea.add(s6);

		} else if (getSarreraKopMax() == 7) {
			sarreraBektorea.add(s1);
			sarreraBektorea.add(s2);
			sarreraBektorea.add(s3);
			sarreraBektorea.add(s4);
			sarreraBektorea.add(s5);
			sarreraBektorea.add(s6);
			sarreraBektorea.add(s7);

		} else if (getSarreraKopMax() == 8) {
			sarreraBektorea.add(s1);
			sarreraBektorea.add(s2);
			sarreraBektorea.add(s3);
			sarreraBektorea.add(s4);
			sarreraBektorea.add(s5);
			sarreraBektorea.add(s6);
			sarreraBektorea.add(s7);
			sarreraBektorea.add(s8);}
	

		
		return sarreraBektorea;
	}

	public boolean barruanDago(int x, int y) {
		if (getSarreraKopMax() == 2) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 15 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 3) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 25 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 4) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 35 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 5) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 45 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 6) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 55 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 7) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 65 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 8) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 75 > y))
				return true;
			else
				return false;

		}
		return false;
	}
	public String getLogika(){
		return logika;
	}
}
